<div class="fsh-pop">
    <input type="password" style="display: none"/>
    <div id="add_form" class="layui-form">
        <input type="hidden" name="hash" value="<%=hash%>">
        <input type="hidden" name="course_id" value="<%=course_id%>">
        <input type="hidden" name="img_url" id="imgUrl">
        <input type="hidden" name="accessory_url" id="attachUrl">
        <input type="hidden" name="resource_url" id="videoUrl" >
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务名称</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" value="<%=course_task%>" class="layui-input"  readonly>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>效果图</label>
            <div class="layui-input-block">
                <div class="layui-upload" id="img">
                    <button type="button" class="layui-btn layui-btn-sm" id="upload_img">上传</button>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>课程视频</label>
            <div class="layui-input-block">
                <div class="layui-upload" id="video">
                    <button type="button" class="layui-btn layui-btn-sm" id="upload_video">上传</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">课程作业</label>
            <div class="layui-input-block">
                <textarea name="desc_ribe" placeholder="填写作业要求（如有）" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">附件</label>
            <div class="layui-input-block">
                <div class="layui-upload" id="attach">
                    <button type="button" class="layui-btn layui-btn-sm" id="upload_attach"> 上传</button>
                </div>
            </div>
        </div>
    </div>

</div>
<style>
    #pic {
        width: 200px;
        height: 100px;
        margin-top: 10px;
    }
</style>
<script type="text/javascript">

    layui.use(['upload', 'form'], function () {
        var upload = layui.upload;
        var form = layui.form;

        //上传图片
        upload.render({
            elem: '#upload_img'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    var html = '</br>';
                    html += '<img src="' + res.link + '" style="width: 200px;height: 100px" alt=""/>';
                    $('#img').append(html);
                    $('#imgUrl').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
            }
        });
        //上传视频
        var videoName;
        upload.render({
            elem: '#upload_video'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                obj.preview(function (index, file, result) {
                    videoName = file.name;
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    var html = '<label style="display: block;line-height: 40px">' + videoName + '</label>';
                    $('#video').append(html);
                    $('#videoUrl').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
            }
        });
        //上传附件
        var attachName;
        upload.render({
            elem: '#upload_attach'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                obj.preview(function (index, file, result) {
                    attachName = file.name;
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    var html = '<label style="display: block;line-height: 40px">' + attachName + '</label>';
                    $('#attach').append(html);
                    $('#attachUrl').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
            }
        });
    });

</script>
